package crud.test;

import crud.dao.DepartmentMapper;
import crud.dao.EmployeeMapper;
import crud.pojo.Department;
import crud.pojo.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.UUID;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class mybatistest {
       @Autowired
       DepartmentMapper departmentMapper;
       @Autowired
       EmployeeMapper employeeMapper;
       @Autowired
       SqlSession sqlSession;

    @Test//测试部门类插入 查询
    public void test1(){
      departmentMapper.insertSelective(new Department(null,"开发部"));
      departmentMapper.insertSelective(new Department(null,"测试部"));
        List<Department> departmentList = departmentMapper.selectall();
        for(Department department:departmentList){
            System.out.println(department);
        }


    }


    @Test//测试员工类插入与查询
    public void test2(){



        employeeMapper.insertSelective(new Employee(null,"李旭阳","男","1234@qq.com",1));


        List<Employee> selectall = employeeMapper.selectall();


        for(Employee employee:selectall){
            System.out.println(employee);
        }




    }

    @Test //批量操作插入
    public void test3(){
        EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
        for (int i = 0; i <1000 ; i++) {
            String uid = UUID.randomUUID().toString().substring(0, 5) + i;
            mapper.insertSelective(new Employee(null,uid,"男",uid+"@lxy.com",1));
        }


    }
}
